//
//  ViewController.m
//  26-Masonry
//
//  Created by 鹏飞罗 on 16/8/18.
//  Copyright © 2016年 罗鹏飞. All rights reserved.
//

#import "ViewController.h"
#import "Masonry.h"
@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
  // 使用Masonry, 不用给初始frame
    UIView *view = [UIView new];
    view.backgroundColor = [UIColor redColor];
//    添加约束前， 需要把试图添加到父试图上
    [self.view addSubview:view];
   //  设置该试图的约束
    [view mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.top.bottom.mas_equalTo(0);
        make.left.mas_equalTo(0);
        make.right.mas_equalTo(0);
        make.top.mas_equalTo(0);
        make.bottom.mas_equalTo(0);
        
    }];
    
//    添加蓝色试图， 宽高各100， 居中显示
    UIView *blueView = [UIView new];
    blueView.backgroundColor = [UIColor blueColor];
    [self.view addSubview:blueView];
    [blueView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.equalTo(view.mas_width).multipliedBy(0.5);
        make.height.mas_equalTo(100);
        make.center.mas_equalTo(0);
    }];
    
    
//    添加黄色视图， 宽高与蓝色相同， 与蓝色相距10
    UIView *yellowView = [UIView new];
    yellowView.backgroundColor = [UIColor yellowColor];
    [self.view addSubview:yellowView];
    [yellowView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.centerX.height.mas_equalTo(blueView);
        make.top.mas_equalTo(blueView.mas_bottom).mas_offset(10);
            }];
//    yellowView.left = self.view.left * 1 + 0;
    // [NSLayoutConstraint constraintWithItem:yellowView attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeLeft multiplier:1 constant:0];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
